# v0.19.0

## MaxProcs 支持配置基于 CPU 使用限制自动识别

###  配置：

```json
{
	"close_graceful" : true,
	"servers":[
		{
			"default_log_path":"stdout",
			"processor": "auto",  // processor 可以是 ”processor“， 整数，或不提供
			"routers":[
				{
					"router_config_name":"server_router",
					"virtual_hosts":[{
						"name":"serverHost",
						"domains": ["*"],
						"routers": [
							{
								"match":{"prefix":"/"},
								"route":{"cluster_name":"serverCluster"}
							}
						]
					}]
				}
			],
			"listeners":[
				{
					"name":"serverListener",
					"address": "127.0.0.1:2046",
					"bind_port": true,
					"filter_chains": [{
						"filters": [
							{
								"type": "proxy",
								"config": {
									"downstream_protocol": "Http1",
									"upstream_protocol": "Http1",
									"router_config_name":"server_router"
								}
							}
						]
					}]
				}
			]
		}
	],
	"cluster_manager":{
		"clusters":[
			{
				"name":"serverCluster",
				"type": "SIMPLE",
				"lb_type": "LB_RANDOM",
				"max_request_per_conn": 1024,
				"conn_buffer_limit_bytes":32768,
				"hosts":[
					{"address":"127.0.0.1:8080"}
				]
			}
		]
	},
	"admin": {
		"address": {
			"socket_address": {
				"address": "0.0.0.0",
				"port_value": 34902
			}
		}
	}
}
```

### processor 为 "auto"

```bash
docker run -it -e GODEBUG=schedtrace=1000 --cpus 1 -v ~/go/src/github.com/mosn/mosn/cmd/mosn/main:/mosnio busybox /mosnio/mosn -c /mosnio/config.json
***
SCHED 1008ms: gomaxprocs=1 idleprocs=1 threads=11 spinningthreads=0 idlethreads=6 runqueue=0 [0]
SCHED 2016ms: gomaxprocs=1 idleprocs=1 threads=11 spinningthreads=0 idlethreads=6 runqueue=0 [0]
SCHED 3025ms: gomaxprocs=1 idleprocs=1 threads=11 spinningthreads=0 idlethreads=6 runqueue=0 [0]
SCHED 4026ms: gomaxprocs=1 idleprocs=1 threads=11 spinningthreads=0 idlethreads=6 runqueue=0 [0]
```

### processor 为 4

```bash
docker run -it -e GODEBUG=schedtrace=1000 --cpus 1 -v ~/go/src/github.com/mosn/mosn/cmd/mosn/main:/mosnio busybox /mosnio/mosn -c /mosnio/config.json
***
SCHED 1004ms: gomaxprocs=4 idleprocs=4 threads=11 spinningthreads=0 idlethreads=6 runqueue=0 [0 0 0 0]
SCHED 2004ms: gomaxprocs=4 idleprocs=4 threads=11 spinningthreads=0 idlethreads=6 runqueue=0 [0 0 0 0]
SCHED 3004ms: gomaxprocs=4 idleprocs=4 threads=11 spinningthreads=0 idlethreads=6 runqueue=0 [0 0 0 0]
SCHED 4005ms: gomaxprocs=4 idleprocs=4 threads=11 spinningthreads=0 idlethreads=6 runqueue=0 [0 0 0 0]
```

### 不提供 processor

```bash
docker run -it -e GODEBUG=schedtrace=1000 --cpus 1 -v ~/go/src/github.com/mosn/mosn/cmd/mosn/main:/mosnio busybox /mosnio/mosn -c /mosnio/config.json
***
SCHED 1000ms: gomaxprocs=6 idleprocs=6 threads=11 spinningthreads=0 idlethreads=6 runqueue=0 [0 0 0 0 0 0]
SCHED 2007ms: gomaxprocs=6 idleprocs=6 threads=11 spinningthreads=0 idlethreads=6 runqueue=0 [0 0 0 0 0 0]
SCHED 3017ms: gomaxprocs=6 idleprocs=6 threads=11 spinningthreads=0 idlethreads=6 runqueue=0 [0 0 0 0 0 0]
```

6 是宿主机核心数。

## AccessLog 获取变量失败时，使用”-”代替

`log_format`: `[%start_time%] %request_received_duration% %response_received_duration% %bytes_sent% %bytes_received% %protocol% %response_code% %duration% %response_flag% %response_code% %upstream_local_address% %downstream_local_address% %downstream_remote_address% %upstream_host% %upstream_transport_failure_reason% %upstream_cluster%`

输出的 accesslog：

```bash
[2020/11/30 13:42:38.571] 569.975µs 904.411µs 415 0 Http1 200 981.633µs false 200 127.0.0.1:8080 127.0.0.1:2046 127.0.0.1:50383 - 0xc8 serverCluster
```

## mixer filter 缺少默认配置，导致空指针

配置：

```json
"stream_filters": [
    {
        "type": "mixer",
        "config": {
        "mixer_attributes": {
            "attributes": {
            "mesh1.ip": {
                "bytes_value": "AQEBAQ=="
            },
            "target.namespace": {
                "string_value": "XYZ222"
            },
            "target.uid": {
                "string_value": "POD222"
            }
            }
        }
        }
    }
]
```

### log before 

```bash
2020-11-30 17:11:42,590 [ERROR] [2,c0a8022e160672750259010018187] [proxy] [downstream] writeLog panic runtime error: invalid memory address or nil pointer dereference, downstream &{ID:1 proxy:0xc00070e5b0 route:0xc0003031c0 cluster:0xc000387200 element:0xc00003da10 bufferLimit:0 timeout:{GlobalTimeout:60000000000 TryTimeout:0} retryState:0xc00039e190 requestInfo:0xc0001be230 responseSender:0xc0001ba000 upstreamRequest:0xc0001be1a8 perRetryTimer:<nil> responseTimer:<nil> downstreamReqHeaders:{RequestHeader:0xc0001ba088 EmptyValueHeaders:map[]} downstreamReqDataBuf:<nil> downstreamReqTrailers:<nil> downstreamRespHeaders:{ResponseHeader:0xc0001ba7a8 EmptyValueHeaders:map[]} downstreamRespDataBuf:0xc0002ea3c0 downstreamRespTrailers:<nil> downstreamResponseStarted:true downstreamRecvDone:true upstreamRequestSent:true upstreamProcessDone:true noConvert:false directResponse:false oneway:false notify:0xc0001a43c0 downstreamReset:0 downstreamCleaned:1 upstreamReset:0 reuseBuffer:1 resetReason: senderFilters:[] senderFiltersIndex:0 receiverFilters:[0xc000184020] receiverFiltersIndex:0 receiverFiltersAgainPhase:0 context:0xc000703080 streamAccessLogs:[0xc00039e0a0] logDone:1 snapshot:0xc00071ac00}

```

### log after

```bash
2020-11-30 17:15:50,262 [INFO] remote addr: 127.0.0.1:8080, network: tcp
2020-11-30 17:15:50,263 [ERROR] get mixer server cluster config error, report cluster: mixer_server
2020-11-30 17:15:50,263 [INFO] [network] [read loop] do read err: EOF
2020-11-30 17:15:50,263 [ERROR] get mixer server cluster config error, report cluster: mixer_server
2020-11-30 17:15:50,263 [ERROR] get mixer server cluster config error, report cluster: mixer_server
2020-11-30 17:15:50,263 [ERROR] get mixer server cluster config error, report cluster: mixer_server
```

没有空指针了（报错是因为没有起 mixer）。
